class ZipcodeValidator < ActiveModel::EachValidator
  def validate_each(object, attribute, value)
    unless value.nil? or value.empty?
      unless value =~ %r{\d{5}(-\d{4})?}
        object.errors[attribute] << (options[:message] || "should be 12345 or 12345-1234") 
      end
    end
  end
end